package org.blogwu.learn.threadLearn.重入锁学习;

import java.util.concurrent.locks.ReentrantLock;

public class Demo1 {
    static ReentrantLock reentrantLock = new ReentrantLock();


    public static void main(String[] args) {
        Thread t1 = new Thread(() -> {
            reentrantLock.lock();
            try {
                System.out.println("t1获取锁");
                Thread.sleep(50000);
                System.out.println("t1获取锁执行完毕");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });
        t1.start();
        Thread t2 = new Thread(() -> {

            try {
                reentrantLock.lock();
                System.out.println("t2获取锁");
                Thread.sleep(50000);
                System.out.println("t2获取锁执行完毕");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });

        t2.start();
        try {
            System.out.println("main睡眠");
            Thread.sleep(15000);
            System.out.println("main睡眠完毕");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        t2.interrupt();
        System.out.println("ttt2:" + t2.isInterrupted());


    }
}
